/*
 * @Author: zhangweixin 
 * @Date: 2018-12-07 15:35:03 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-12-07 17:29:40
 */

import {
GET_ORDER_LIST_REQUEST,
GET_ORDER_LIST_SUCCESS,
GET_ORDER_LIST_FAIL,

GET_ORDER_DETAIL_REQUEST,
GET_ORDER_DETAIL_SUCCESS,
GET_ORDER_DETAIL_FAIL
} from '../constants/actionTypes';

import ENV from 'ENV';
import 'whatwg-fetch';

function getOrderListRequest(){
  return {
    type:GET_ORDER_LIST_REQUEST
  }
}
function getOrderListSuccess(data){
  return{
    data:data,
    type:GET_ORDER_LIST_SUCCESS
  }
}
function getOrderListFail(){
  return {
    type: GET_ORDER_LIST_FAIL
  }
}
export function getOrderList(queryObj) {
  return function (dispatch) {
      dispatch(getOrderListRequest());

      return fetch(`${ENV.ApiRoot}/orders`,{
        method:'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          name: 'Hubot',
          login: 'hubot',
        })
      })
          .then((response => {
              return response.json()
          }))
          .then((json) => {
                  dispatch(getOrderListSuccess(json))
              }
          ).catch(
              () => {
                  dispatch(getOrderListFail());
              }
          )
  }
}